package com.lxyk.springcloud.config;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

/**
 * @ClassName ApplicationContextConfig
 * @Description TODO
 * @Author FJQ
 * @Date 2022/11/14 22:00
 * @Version 1.0
 **/
@Configuration
public class ApplicationContextConfig {

    @Bean
    public IRule myRule() {
        // RandomRule 为随机策略  默认是轮询策略
        return  new RandomRule();
    }

    @Bean
    @LoadBalanced //赋予RestTemplate负载均衡的能力
    public RestTemplate getRestTemplate(){
        return new RestTemplate();
    }
}
